package top.wyix.module.test.controller.admin.framework;

import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.wyix.framework.common.pojo.CommonResult;
import top.wyix.framework.common.util.json.JsonUtils;
import top.wyix.module.test.controller.admin.framework.vo.ValDemoReq;
import top.wyix.module.test.service.IValidateService;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wangdx
 */
@RestController
@RequestMapping("/test/framework/*")
public class FrameWorkTestController {
    @Autowired
    private IValidateService validateService;

    @GetMapping("val2")
    public Object val2(ValDemoReq msg) {
//        System.out.println(validateService.validate(2, "null"));
        System.out.println(validateService.validateEn(new ValDemoReq().setMobile("").setCode("")));
        return CommonResult.success(msg);
    }

    @GetMapping("val")
    public Object val(ValDemoReq msg) {
        System.out.println(validateService.hello(11, "wdx"));
        return CommonResult.success(msg);
    }

    @GetMapping("commonResult")
    public CommonResult<Map<String, Object>> commonResult(String msg) {
        Map<String, Object> re = new HashMap<>();
        re.put("name", null);
        re.put("age", 88);
        re.put("msg", msg);
        re.put("data", new Date());
        re.put("TracerUtils", TraceContext.traceId());
        re.put("list", List.of("地方", "Fdf"));
        return CommonResult.success(re);
    }

    @GetMapping("json")
    public CommonResult<String> json(String msg) {
        Map<String, Object> re = new HashMap<>();
        re.put("name", null);
        re.put("age", 88);
        re.put("msg", msg);
        re.put("data", new Date());
        re.put("TracerUtils", TraceContext.traceId());
        re.put("list", List.of("地方", "Fdf"));
        return CommonResult.success(JsonUtils.toJsonString(re));
    }
}
